package com.cn.wanxi.dao.impl;

import com.cn.wanxi.dao.CuisineDao;
import com.cn.wanxi.model.CuisineModel;
import com.cn.wanxi.model.UserModel;
import com.cn.wanxi.util.JDBC;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CuisineImpl implements CuisineDao {
    @Override
    public int add(CuisineModel cuisineModel) {
        return 0;
    }

    @Override
    public int update(CuisineModel cuisineModel) {
        return 0;
    }

    @Override
    public int delete(CuisineModel cuisineModel) {
        return 0;
    }

    @Override
    public List<CuisineModel> findAll(CuisineModel cuisineModel) {
        String sql = "select * from cuisine";

        return getList(sql);
    }

    private List<CuisineModel> getList(String sql) {
        List<CuisineModel> list = new ArrayList<>();
        ResultSet query = JDBC.query(sql);
        try {
            while (query.next()) {
                CuisineModel model = new CuisineModel();
                model.setId(query.getInt("id"));
                model.setName(query.getString("name"));
                list.add(model);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }

    @Override
    public CuisineModel findById(CuisineModel cuisineModel) {
        return null;
    }

    @Override
    public int count(CuisineModel cuisineModel) {
        return 0;
    }
}
